package com.jf.cloud.combo.listener;

import com.jf.cloud.api.product.feign.ShopCartFeignClient;
import com.jf.cloud.combo.bo.ComboSpuCountChangeNotifyBO;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zz
 * @date 2022/11/30 16:39
 * 套餐修改商品起搭数时异步修改以后购物车商品数量
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.COMBO_SPU_COUNT_CHANGE,consumerGroup = RocketMqConstant.COMBO_SPU_COUNT_CHANGE)
public class ComboSpuCountChangeListener implements RocketMQListener<List<ComboSpuCountChangeNotifyBO>> {

    @Autowired
    private ShopCartFeignClient shopCartFeignClient;
    @Override
    public void onMessage(List<ComboSpuCountChangeNotifyBO> messageList) {
        for (ComboSpuCountChangeNotifyBO message : messageList) {
            shopCartFeignClient.updateCartComboCount(message.getComboId(),message.getSpuId(),message.getCount());
        }
    }
}
